<script lang="ts" setup>
import type { AiTrainingDatasetSamplesApi } from '#/api/ai/dataset/trainingDatasetSamples';

import { ref } from 'vue';

import { useVbenModal } from '@vben/common-ui';

import { getTrainingDatasetSamples } from '#/api/ai/dataset/trainingDatasetSamples';
import { useDescription } from '#/components/description';

import { useDetailSchema } from '../data';

const formData = ref<AiTrainingDatasetSamplesApi.TrainingDatasetSamples>();

const [Descriptions] = useDescription({
  bordered: true,
  size: 'middle',
  column: 1,
  labelWidth: 120,

  schema: useDetailSchema(),
});

const [Modal, modalApi] = useVbenModal({
  async onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      formData.value = undefined;
      return;
    }
    let data =
      modalApi.getData<AiTrainingDatasetSamplesApi.TrainingDatasetSamples>();
    if (!data || !data.id) {
      return;
    }
    modalApi.lock();
    try {
      data = await getTrainingDatasetSamples(data.id);
      formData.value = data;
    } finally {
      modalApi.unlock();
    }
  },
});
</script>

<template>
  <Modal
    title="查看 数据集数据"
    class="w-[60%]"
    :show-cancel-button="false"
    :show-confirm-button="false"
  >
    <Descriptions :data="formData" class="mx-4" />
  </Modal>
</template>
